package com.wzdigit.wms.raw.controller.report;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.raw.client.request.report.SearchPoHeaderReportRequest;
import com.wzdigit.wms.raw.client.response.report.PoDtlReportResponse;
import com.wzdigit.wms.raw.client.response.report.PoHeaderReportResponse;
import com.wzdigit.wms.raw.constant.RawWareConstant;
import com.wzdigit.wms.raw.service.report.PoReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 采购订单报表
 * @author Administrator
 *
 */
@RestController
@Api(tags = "采购订单报表")
@RequestMapping(value = RawWareConstant.API_VERSION)
public class PoReportController {
	
	public static final String REQUEST_MODEL = "/poreport";

    @Autowired
    private PoReportService poReportService;

    @ApiOperation(value = "主档", notes = "主档")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUEST_MODEL + "/selectPoReportList")
    public PagerInfo<List<PoHeaderReportResponse>> selectPoReportList(
    		SearchPoHeaderReportRequest search, Pager<?> pager,
            HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
    	try {
            return poReportService.selectPoReportList(search, pager);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    @ApiOperation(value = "明细", notes = "明细")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUEST_MODEL + "/selectPoDtlReportList")
    public List<PoDtlReportResponse> selectPoDtlReportList(
    		@ApiParam(value = "采购订单表头ID", required = true) 
    		@RequestParam(required = true) Integer poHeaderId, 
    		HttpServletRequest servletRequest, 
    		HttpServletResponse servletResponse) {
    	try {
            return poReportService.selectPoDtlReportList(poHeaderId);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    @ApiOperation(value = "导出", notes = "导出")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @GetMapping(value = REQUEST_MODEL + "/exportPoReportList")
    public void exportPoReportList(
    		SearchPoHeaderReportRequest search, 
    		HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
    	try {
            poReportService.exportPoReportList(search, servletRequest, servletResponse);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
}